package com.wondertek.poms.service.controller;

import com.wondertek.poms.common.log.MethodLog;
import com.wondertek.poms.common.vo.ResultBean;
import com.wondertek.poms.core.service.IAdvanceSaleService;
import com.wondertek.poms.dao.po.AdvanceSale;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author evan0213
 * @description 超前点播模版计费详情web接口
 */
@Api(value = "AdvanceSaleController", description = "支付方式 接口")
@RestController
@RequestMapping("advance-sale")
public class AdvanceSaleController {

	@Autowired
	private IAdvanceSaleService advanceSaleService;


	/**
	 * 列表
	 *
	 * @param modelId 模式计费id
	 * @return 所有计费详情
	 */
	@ApiOperation(value = "超前点播模版计费详情 列表", notes = "超前点播模版计费详情 列表")
	@GetMapping("/list")
	@MethodLog(module = "支付方式列表")
	public ResultBean list(Long modelId) {
		if (modelId == null) {
			return ResultBean.error("modelId不能为空");
		}
		List<AdvanceSale> advanceSaleList = advanceSaleService.findAllByModelId(modelId);
		return ResultBean.ok(advanceSaleList);
	}


	/**
	 * 、
	 * 超前点播模版计费详情删除
	 *
	 * @param ids 超前点播模版计费详情id拼接字符串，以英文逗号分隔
	 * @return 删除结果
	 */
	@ApiOperation(value = "超前点播模版计费详情 删除", notes = "超前点播模版计费详情 删除")
	@ApiImplicitParam(name = "ids", required = true, dataType = "String", value = "超前点播模版计费详情id拼接字符串，以英文逗号分隔")
	@DeleteMapping(value = "/del")
	@MethodLog(module = "支付方式删除", insertDB = true, opterate = 3)
	public ResultBean delete(String ids) {
		if (StringUtils.isNotBlank(ids)) {
			String[] idsArr = ids.split(",");
			for (String id : idsArr) {
				advanceSaleService.deleteLogic(Long.parseLong(id));
			}
			return ResultBean.ok();
		} else {
			return ResultBean.error("id不能为空");
		}
	}

}
